import Cookies from 'js-cookie'

// token 缓存key
const tokenKey = 'wltx:user:token'

// 账号信息缓存key
const rememberUserKey = 'wltx:user:name'

// 手机号缓存key
const rememberMobileKey = 'wltx:user:mobile'

// 商户号缓存key
const rememberMerchantsCodeKey = 'wltx:login:merchants:code'

// 缓存用户token
const setUserToken = (userToken) => {
  Cookies.set(tokenKey, userToken)
}

// 获取用户token
const getUserToken = () => {
  return Cookies.get(tokenKey)
}

// 移除用户token
const removeUserToken = () => {
  Cookies.remove(tokenKey)
}

// 缓存用户账号
const setRememberUser = (username) => {
  Cookies.set(rememberUserKey, username, { expires: 30})
}

// 获取用户账号信息
const getRememberUser = () => {
  return Cookies.get(rememberUserKey)
}

// 移除用户账号信息
const removeRememberUser = () => {
  Cookies.remove(rememberUserKey)
}

// 缓存手机号
const setRememberPhone = (mobile) => {
  Cookies.set(rememberMobileKey, mobile, { expires: 30 })
}

// 缓存手机号
const getRememberPhone = () => {
  return Cookies.get(rememberMobileKey)
}

// 移除缓存手机号
const removeRememberPhone = () => {
   Cookies.remove(rememberMobileKey)
}

// 缓存商户号
const setLoginMerchantsCode = (merchantsCode) => {
  Cookies.set(rememberMerchantsCodeKey, merchantsCode, { expires: 30 })
}

// 缓存商户号
const getLoginMerchantsCode = () => {
  return Cookies.get(rememberMerchantsCodeKey)
}

// 移除商户号
const removeLoginMerchantsCode = () => {
  Cookies.remove(rememberMerchantsCodeKey)
}

const storage = {
  setUserToken,
  getUserToken,
  removeUserToken,
  setRememberUser,
  getRememberUser,
  setRememberPhone,
  getRememberPhone,
  removeRememberUser,
  removeRememberPhone,
  setLoginMerchantsCode,
  getLoginMerchantsCode,
  removeLoginMerchantsCode
}

export default storage
